from concurrent.futures import ProcessPoolExecutor
from concurrent.futures import ThreadPoolExecutor
import time


class ConnectionPool:
    def __init__(self):
        self.pool = ThreadPoolExecutor(max_workers=2)

    def add_connection(self, connection):
        future = self.pool.submit(connection.keep, 3)
        time.sleep(1)

    def require(self):
        pass


class Connection:
    def __init__(self):
        pass

    def keep(self, number):
        time.sleep(number)
        print 'finish'

    def do(self):
        print "do it"

connectionPool = ConnectionPool()
connection = Connection()
connectionPool.add_connection(connection)
connection.do()


# def test(msg):
#     for i in xrange(10):
#         time.sleep(1)
#         print msg
#
# with ThreadPoolExecutor(max_workers=2) as pool:
#     future1 = pool.submit(test, 'ee')
#     print 'ddd'
#     future2 = pool.submit(test, 'aa')
#
#     future3 = pool.submit(test, 'dd')
#     future4 = pool.submit(test, 'nn')
